package com.hkbigdata.sybx.mapper;

import com.hkbigdata.sybx.bean.ContactUs;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author liuanbo
 * @creat 2025-05-29-19:42
 * @see 2194550857@qq.com
 */
@Mapper
public interface ContactUsMapper {
    @Insert("insert into contact_us(user_id,name,user_phone,user_email,leave_word)" +
            " values (#{userId}, #{name}, #{userPhone}, #{userEmail}, #{leaveWord})")
    int ContactUsInsert(ContactUs contactUs);
    /** 根据记录ID删除联系信息 */
    @Delete("DELETE FROM contact_us WHERE id = #{id}")
    int deleteContactUsById(String id);

    /** 根据用户ID删除所有联系信息 */
    @Delete("DELETE FROM contact_us WHERE user_id = #{userId}")
    int deleteContactUsByUserId(String userId);

    /** 更新联系信息 */
    @Update("UPDATE contact_us SET " +
            "name = #{name}, user_phone = #{userPhone}, " +
            "user_email = #{userEmail}, leave_word = #{leaveWord} " +
            "WHERE id = #{id}")
    int updateContactUs(ContactUs contactUs);

    /** 根据记录ID查询单条联系信息 */
    @Select("SELECT id, name, user_phone as userPhone, " +
            "user_email as userEmail, leave_word as leaveWord, user_id as userId " +
            "FROM contact_us WHERE id = #{id}")
    ContactUs getContactUsById(String id);

    /** 根据用户ID查询所有联系信息 */
    @Select("SELECT id, name, user_phone as userPhone, " +
            "user_email as userEmail, leave_word as leaveWord, user_id as userId " +
            "FROM contact_us WHERE user_id = #{userId}")
    List<ContactUs> getContactUsByUserId(String userId);

    /** 查询所有联系信息 */
    @Select("SELECT id, name, user_phone as userPhone, " +
            "user_email as userEmail, leave_word as leaveWord, user_id as userId " +
            "FROM contact_us")
    List<ContactUs> getAllContactUs();
}
